
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 11/05/2013 21:02:20
-- Generated from EDMX file: D:\Projects\Own\LzSys\source\Sys.Model\Entities.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [LzSys];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_SysButton_SysMenuButton]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_MenuButtons] DROP CONSTRAINT [FK_SysButton_SysMenuButton];
GO
IF OBJECT_ID(N'[dbo].[FK_SysDepartment_SysUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_Users] DROP CONSTRAINT [FK_SysDepartment_SysUser];
GO
IF OBJECT_ID(N'[dbo].[FK_SysDictionary_GenNew]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Gen_News] DROP CONSTRAINT [FK_SysDictionary_GenNew];
GO
IF OBJECT_ID(N'[dbo].[FK_SysDicType_SysDictionary]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_Dictionaries] DROP CONSTRAINT [FK_SysDicType_SysDictionary];
GO
IF OBJECT_ID(N'[dbo].[FK_SysMenu_SysMenuButton]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_MenuButtons] DROP CONSTRAINT [FK_SysMenu_SysMenuButton];
GO
IF OBJECT_ID(N'[dbo].[FK_SysMenuButton_SysRoleMenuButton]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_RoleMenuButtons] DROP CONSTRAINT [FK_SysMenuButton_SysRoleMenuButton];
GO
IF OBJECT_ID(N'[dbo].[FK_SysMenuButton_SysUserMenuButton]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_UserMenuButtons] DROP CONSTRAINT [FK_SysMenuButton_SysUserMenuButton];
GO
IF OBJECT_ID(N'[dbo].[FK_SysRole_SysRoleMenuButton]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_RoleMenuButtons] DROP CONSTRAINT [FK_SysRole_SysRoleMenuButton];
GO
IF OBJECT_ID(N'[dbo].[FK_SysRole_SysUserRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_UserRoles] DROP CONSTRAINT [FK_SysRole_SysUserRole];
GO
IF OBJECT_ID(N'[dbo].[FK_SysUser_SysUserMenuButton]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_UserMenuButtons] DROP CONSTRAINT [FK_SysUser_SysUserMenuButton];
GO
IF OBJECT_ID(N'[dbo].[FK_SysUser_SysUserRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sys_UserRoles] DROP CONSTRAINT [FK_SysUser_SysUserRole];
GO
IF OBJECT_ID(N'[dbo].[FK_TourRoute_TourRouteScenic]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tour_RouteScenics] DROP CONSTRAINT [FK_TourRoute_TourRouteScenic];
GO
IF OBJECT_ID(N'[dbo].[FK_TourScenic_TourRouteScenic]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tour_RouteScenics] DROP CONSTRAINT [FK_TourScenic_TourRouteScenic];
GO
IF OBJECT_ID(N'[dbo].[FK_TourScenic_TourTicketScenic]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tour_TicketScenics] DROP CONSTRAINT [FK_TourScenic_TourTicketScenic];
GO
IF OBJECT_ID(N'[dbo].[FK_TourTicket_TourTicketScenic]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tour_TicketScenics] DROP CONSTRAINT [FK_TourTicket_TourTicketScenic];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Gen_Contents]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Gen_Contents];
GO
IF OBJECT_ID(N'[dbo].[Gen_Focus]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Gen_Focus];
GO
IF OBJECT_ID(N'[dbo].[Gen_News]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Gen_News];
GO
IF OBJECT_ID(N'[dbo].[Sys_Buttons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_Buttons];
GO
IF OBJECT_ID(N'[dbo].[Sys_Departments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_Departments];
GO
IF OBJECT_ID(N'[dbo].[Sys_Dictionaries]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_Dictionaries];
GO
IF OBJECT_ID(N'[dbo].[Sys_DicTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_DicTypes];
GO
IF OBJECT_ID(N'[dbo].[Sys_Logs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_Logs];
GO
IF OBJECT_ID(N'[dbo].[Sys_MenuButtons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_MenuButtons];
GO
IF OBJECT_ID(N'[dbo].[Sys_Menus]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_Menus];
GO
IF OBJECT_ID(N'[dbo].[Sys_RoleMenuButtons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_RoleMenuButtons];
GO
IF OBJECT_ID(N'[dbo].[Sys_Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_Roles];
GO
IF OBJECT_ID(N'[dbo].[Sys_Settings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_Settings];
GO
IF OBJECT_ID(N'[dbo].[Sys_UserMenuButtons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_UserMenuButtons];
GO
IF OBJECT_ID(N'[dbo].[Sys_UserRoles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_UserRoles];
GO
IF OBJECT_ID(N'[dbo].[Sys_Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sys_Users];
GO
IF OBJECT_ID(N'[dbo].[Tour_Cars]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Cars];
GO
IF OBJECT_ID(N'[dbo].[Tour_Foods]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Foods];
GO
IF OBJECT_ID(N'[dbo].[Tour_Hotels]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Hotels];
GO
IF OBJECT_ID(N'[dbo].[Tour_Images]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Images];
GO
IF OBJECT_ID(N'[dbo].[Tour_Meetings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Meetings];
GO
IF OBJECT_ID(N'[dbo].[Tour_Programs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Programs];
GO
IF OBJECT_ID(N'[dbo].[Tour_Recreations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Recreations];
GO
IF OBJECT_ID(N'[dbo].[Tour_Routes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Routes];
GO
IF OBJECT_ID(N'[dbo].[Tour_RouteScenics]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_RouteScenics];
GO
IF OBJECT_ID(N'[dbo].[Tour_Rurals]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Rurals];
GO
IF OBJECT_ID(N'[dbo].[Tour_Scenics]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Scenics];
GO
IF OBJECT_ID(N'[dbo].[Tour_Shoppings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Shoppings];
GO
IF OBJECT_ID(N'[dbo].[Tour_Tickets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Tickets];
GO
IF OBJECT_ID(N'[dbo].[Tour_TicketScenics]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_TicketScenics];
GO
IF OBJECT_ID(N'[dbo].[Tour_Travels]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tour_Travels];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Sys_Menus'
CREATE TABLE [dbo].[Sys_Menus] (
    [ID] nvarchar(32)  NOT NULL,
    [Icon] nvarchar(80)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Tag] nvarchar(80)  NOT NULL,
    [Link] nvarchar(80)  NULL,
    [Type] nvarchar(80)  NOT NULL,
    [Path] nvarchar(max)  NOT NULL,
    [Parent] nvarchar(32)  NULL,
    [IntSort] int  NOT NULL,
    [IsVisible] bit  NOT NULL
);
GO

-- Creating table 'Sys_Buttons'
CREATE TABLE [dbo].[Sys_Buttons] (
    [ID] nvarchar(32)  NOT NULL,
    [Icon] nvarchar(80)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Type] nvarchar(80)  NOT NULL,
    [IntSort] int  NOT NULL,
    [Function] nvarchar(80)  NOT NULL
);
GO

-- Creating table 'Sys_MenuButtons'
CREATE TABLE [dbo].[Sys_MenuButtons] (
    [ID] nvarchar(32)  NOT NULL,
    [IntSort] int  NOT NULL,
    [MenuID] nvarchar(32)  NOT NULL,
    [ButtonID] nvarchar(32)  NOT NULL
);
GO

-- Creating table 'Sys_Users'
CREATE TABLE [dbo].[Sys_Users] (
    [ID] nvarchar(32)  NOT NULL,
    [UserName] nvarchar(80)  NOT NULL,
    [PassWord] nvarchar(80)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Tag] nvarchar(80)  NULL,
    [Mobile] nvarchar(80)  NULL,
    [Tel] nvarchar(80)  NULL,
    [Email] nvarchar(80)  NULL,
    [IsSuper] bit  NOT NULL,
    [IsVisible] bit  NOT NULL,
    [InsertTime] datetime  NOT NULL,
    [DepartmentID] nvarchar(32)  NOT NULL
);
GO

-- Creating table 'Sys_Roles'
CREATE TABLE [dbo].[Sys_Roles] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [IntSort] int  NOT NULL,
    [IsVisible] bit  NOT NULL,
    [Remark] nvarchar(280)  NULL
);
GO

-- Creating table 'Sys_UserRoles'
CREATE TABLE [dbo].[Sys_UserRoles] (
    [ID] nvarchar(32)  NOT NULL,
    [UserID] nvarchar(32)  NOT NULL,
    [RoleID] nvarchar(32)  NOT NULL
);
GO

-- Creating table 'Sys_RoleMenuButtons'
CREATE TABLE [dbo].[Sys_RoleMenuButtons] (
    [ID] nvarchar(32)  NOT NULL,
    [RoleID] nvarchar(32)  NOT NULL,
    [MenuButtonID] nvarchar(32)  NOT NULL
);
GO

-- Creating table 'Sys_UserMenuButtons'
CREATE TABLE [dbo].[Sys_UserMenuButtons] (
    [ID] nvarchar(32)  NOT NULL,
    [UserID] nvarchar(32)  NOT NULL,
    [MenuButtonID] nvarchar(32)  NOT NULL
);
GO

-- Creating table 'Sys_Settings'
CREATE TABLE [dbo].[Sys_Settings] (
    [ID] nvarchar(32)  NOT NULL,
    [Group] nvarchar(80)  NOT NULL,
    [Tag] nvarchar(80)  NOT NULL,
    [Content] nvarchar(max)  NULL
);
GO

-- Creating table 'Sys_Departments'
CREATE TABLE [dbo].[Sys_Departments] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Path] nvarchar(max)  NOT NULL,
    [Parent] nvarchar(32)  NULL,
    [IntSort] int  NOT NULL,
    [Remark] nvarchar(280)  NULL
);
GO

-- Creating table 'Sys_Dictionaries'
CREATE TABLE [dbo].[Sys_Dictionaries] (
    [ID] nvarchar(80)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Tag] nvarchar(80)  NULL,
    [DicTypeID] nvarchar(32)  NOT NULL,
    [Path] nvarchar(max)  NOT NULL,
    [Parent] nvarchar(32)  NULL,
    [IntSort] int  NOT NULL,
    [IsVisible] bit  NOT NULL,
    [Remark] nvarchar(280)  NULL
);
GO

-- Creating table 'Sys_DicTypes'
CREATE TABLE [dbo].[Sys_DicTypes] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Tag] nvarchar(80)  NOT NULL,
    [IntSort] int  NOT NULL
);
GO

-- Creating table 'Gen_News'
CREATE TABLE [dbo].[Gen_News] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Img] nvarchar(80)  NULL,
    [Top] bit  NOT NULL,
    [Author] nvarchar(80)  NOT NULL,
    [Source] nvarchar(80)  NOT NULL,
    [Content] nvarchar(max)  NULL,
    [DictionaryID] nvarchar(80)  NOT NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL,
    [Keywords] nvarchar(280)  NULL,
    [Description] nvarchar(280)  NULL
);
GO

-- Creating table 'Tour_Scenics'
CREATE TABLE [dbo].[Tour_Scenics] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Img] nvarchar(80)  NULL,
    [Top] bit  NOT NULL,
    [Virtual] nvarchar(80)  NULL,
    [Voice] nvarchar(80)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Images'
CREATE TABLE [dbo].[Tour_Images] (
    [ID] nvarchar(32)  NOT NULL,
    [TableID] nvarchar(32)  NOT NULL,
    [Tag] nvarchar(80)  NOT NULL,
    [Img] nvarchar(80)  NOT NULL,
    [IsCover] bit  NOT NULL,
    [IntSort] int  NOT NULL,
    [InsertTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Hotels'
CREATE TABLE [dbo].[Tour_Hotels] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Price] nvarchar(80)  NOT NULL,
    [Stars] int  NOT NULL,
    [Tel] nvarchar(80)  NULL,
    [Link] nvarchar(80)  NULL,
    [Address] nvarchar(280)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Gen_Contents'
CREATE TABLE [dbo].[Gen_Contents] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Tag] nvarchar(80)  NULL,
    [IsVisible] bit  NOT NULL,
    [Remark] nvarchar(80)  NULL,
    [Content] nvarchar(max)  NULL,
    [IntSort] int  NOT NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Gen_Focus'
CREATE TABLE [dbo].[Gen_Focus] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Link] nvarchar(80)  NULL,
    [Img] nvarchar(80)  NOT NULL,
    [Group] nvarchar(80)  NOT NULL,
    [IntSort] int  NOT NULL,
    [IsVisible] bit  NOT NULL
);
GO

-- Creating table 'Tour_Routes'
CREATE TABLE [dbo].[Tour_Routes] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Price] nvarchar(80)  NULL,
    [Child] nvarchar(80)  NULL,
    [Img] nvarchar(80)  NOT NULL,
    [Departure] nvarchar(80)  NULL,
    [Traffic] nvarchar(80)  NULL,
    [City] nvarchar(80)  NULL,
    [Top] bit  NOT NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_RouteScenics'
CREATE TABLE [dbo].[Tour_RouteScenics] (
    [ID] nvarchar(32)  NOT NULL,
    [IntSort] int  NOT NULL,
    [RouteID] nvarchar(32)  NOT NULL,
    [ScenicID] nvarchar(32)  NOT NULL
);
GO

-- Creating table 'Tour_Tickets'
CREATE TABLE [dbo].[Tour_Tickets] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Price] nvarchar(80)  NULL,
    [Child] nvarchar(80)  NULL,
    [Img] nvarchar(80)  NULL,
    [Top] bit  NOT NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_TicketScenics'
CREATE TABLE [dbo].[Tour_TicketScenics] (
    [ID] nvarchar(32)  NOT NULL,
    [IntSort] int  NOT NULL,
    [TicketID] nvarchar(32)  NOT NULL,
    [ScenicID] nvarchar(32)  NOT NULL
);
GO

-- Creating table 'Tour_Foods'
CREATE TABLE [dbo].[Tour_Foods] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Price] nvarchar(80)  NULL,
    [Type] nvarchar(80)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Travels'
CREATE TABLE [dbo].[Tour_Travels] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Tel] nvarchar(80)  NULL,
    [Link] nvarchar(80)  NULL,
    [Address] nvarchar(280)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Programs'
CREATE TABLE [dbo].[Tour_Programs] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Time] nvarchar(80)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Meetings'
CREATE TABLE [dbo].[Tour_Meetings] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Price] nvarchar(80)  NULL,
    [Time] nvarchar(80)  NULL,
    [Address] nvarchar(280)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Cars'
CREATE TABLE [dbo].[Tour_Cars] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Price] nvarchar(80)  NULL,
    [Type] nvarchar(80)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Rurals'
CREATE TABLE [dbo].[Tour_Rurals] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Price] nvarchar(80)  NOT NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Recreations'
CREATE TABLE [dbo].[Tour_Recreations] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Price] nvarchar(80)  NOT NULL,
    [Type] nvarchar(80)  NULL,
    [Address] nvarchar(280)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Tour_Shoppings'
CREATE TABLE [dbo].[Tour_Shoppings] (
    [ID] nvarchar(32)  NOT NULL,
    [Name] nvarchar(80)  NOT NULL,
    [Address] nvarchar(280)  NULL,
    [Content] nvarchar(max)  NULL,
    [InsertTime] datetime  NOT NULL,
    [UpdateTime] datetime  NOT NULL
);
GO

-- Creating table 'Sys_Logs'
CREATE TABLE [dbo].[Sys_Logs] (
    [ID] nvarchar(32)  NOT NULL,
    [UserID] nvarchar(32)  NULL,
    [Table] nvarchar(80)  NULL,
    [Type] nvarchar(80)  NULL,
    [Text] nvarchar(max)  NULL,
    [IPAddress] nvarchar(80)  NULL,
    [InsertTime] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Sys_Menus'
ALTER TABLE [dbo].[Sys_Menus]
ADD CONSTRAINT [PK_Sys_Menus]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_Buttons'
ALTER TABLE [dbo].[Sys_Buttons]
ADD CONSTRAINT [PK_Sys_Buttons]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_MenuButtons'
ALTER TABLE [dbo].[Sys_MenuButtons]
ADD CONSTRAINT [PK_Sys_MenuButtons]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_Users'
ALTER TABLE [dbo].[Sys_Users]
ADD CONSTRAINT [PK_Sys_Users]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_Roles'
ALTER TABLE [dbo].[Sys_Roles]
ADD CONSTRAINT [PK_Sys_Roles]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_UserRoles'
ALTER TABLE [dbo].[Sys_UserRoles]
ADD CONSTRAINT [PK_Sys_UserRoles]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_RoleMenuButtons'
ALTER TABLE [dbo].[Sys_RoleMenuButtons]
ADD CONSTRAINT [PK_Sys_RoleMenuButtons]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_UserMenuButtons'
ALTER TABLE [dbo].[Sys_UserMenuButtons]
ADD CONSTRAINT [PK_Sys_UserMenuButtons]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_Settings'
ALTER TABLE [dbo].[Sys_Settings]
ADD CONSTRAINT [PK_Sys_Settings]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_Departments'
ALTER TABLE [dbo].[Sys_Departments]
ADD CONSTRAINT [PK_Sys_Departments]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_Dictionaries'
ALTER TABLE [dbo].[Sys_Dictionaries]
ADD CONSTRAINT [PK_Sys_Dictionaries]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_DicTypes'
ALTER TABLE [dbo].[Sys_DicTypes]
ADD CONSTRAINT [PK_Sys_DicTypes]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Gen_News'
ALTER TABLE [dbo].[Gen_News]
ADD CONSTRAINT [PK_Gen_News]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Scenics'
ALTER TABLE [dbo].[Tour_Scenics]
ADD CONSTRAINT [PK_Tour_Scenics]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Images'
ALTER TABLE [dbo].[Tour_Images]
ADD CONSTRAINT [PK_Tour_Images]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Hotels'
ALTER TABLE [dbo].[Tour_Hotels]
ADD CONSTRAINT [PK_Tour_Hotels]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Gen_Contents'
ALTER TABLE [dbo].[Gen_Contents]
ADD CONSTRAINT [PK_Gen_Contents]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Gen_Focus'
ALTER TABLE [dbo].[Gen_Focus]
ADD CONSTRAINT [PK_Gen_Focus]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Routes'
ALTER TABLE [dbo].[Tour_Routes]
ADD CONSTRAINT [PK_Tour_Routes]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_RouteScenics'
ALTER TABLE [dbo].[Tour_RouteScenics]
ADD CONSTRAINT [PK_Tour_RouteScenics]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Tickets'
ALTER TABLE [dbo].[Tour_Tickets]
ADD CONSTRAINT [PK_Tour_Tickets]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_TicketScenics'
ALTER TABLE [dbo].[Tour_TicketScenics]
ADD CONSTRAINT [PK_Tour_TicketScenics]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Foods'
ALTER TABLE [dbo].[Tour_Foods]
ADD CONSTRAINT [PK_Tour_Foods]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Travels'
ALTER TABLE [dbo].[Tour_Travels]
ADD CONSTRAINT [PK_Tour_Travels]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Programs'
ALTER TABLE [dbo].[Tour_Programs]
ADD CONSTRAINT [PK_Tour_Programs]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Meetings'
ALTER TABLE [dbo].[Tour_Meetings]
ADD CONSTRAINT [PK_Tour_Meetings]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Cars'
ALTER TABLE [dbo].[Tour_Cars]
ADD CONSTRAINT [PK_Tour_Cars]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Rurals'
ALTER TABLE [dbo].[Tour_Rurals]
ADD CONSTRAINT [PK_Tour_Rurals]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Recreations'
ALTER TABLE [dbo].[Tour_Recreations]
ADD CONSTRAINT [PK_Tour_Recreations]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tour_Shoppings'
ALTER TABLE [dbo].[Tour_Shoppings]
ADD CONSTRAINT [PK_Tour_Shoppings]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sys_Logs'
ALTER TABLE [dbo].[Sys_Logs]
ADD CONSTRAINT [PK_Sys_Logs]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [MenuID] in table 'Sys_MenuButtons'
ALTER TABLE [dbo].[Sys_MenuButtons]
ADD CONSTRAINT [FK_SysMenu_SysMenuButton]
    FOREIGN KEY ([MenuID])
    REFERENCES [dbo].[Sys_Menus]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysMenu_SysMenuButton'
CREATE INDEX [IX_FK_SysMenu_SysMenuButton]
ON [dbo].[Sys_MenuButtons]
    ([MenuID]);
GO

-- Creating foreign key on [ButtonID] in table 'Sys_MenuButtons'
ALTER TABLE [dbo].[Sys_MenuButtons]
ADD CONSTRAINT [FK_SysButton_SysMenuButton]
    FOREIGN KEY ([ButtonID])
    REFERENCES [dbo].[Sys_Buttons]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysButton_SysMenuButton'
CREATE INDEX [IX_FK_SysButton_SysMenuButton]
ON [dbo].[Sys_MenuButtons]
    ([ButtonID]);
GO

-- Creating foreign key on [UserID] in table 'Sys_UserRoles'
ALTER TABLE [dbo].[Sys_UserRoles]
ADD CONSTRAINT [FK_SysUser_SysUserRole]
    FOREIGN KEY ([UserID])
    REFERENCES [dbo].[Sys_Users]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysUser_SysUserRole'
CREATE INDEX [IX_FK_SysUser_SysUserRole]
ON [dbo].[Sys_UserRoles]
    ([UserID]);
GO

-- Creating foreign key on [RoleID] in table 'Sys_UserRoles'
ALTER TABLE [dbo].[Sys_UserRoles]
ADD CONSTRAINT [FK_SysRole_SysUserRole]
    FOREIGN KEY ([RoleID])
    REFERENCES [dbo].[Sys_Roles]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysRole_SysUserRole'
CREATE INDEX [IX_FK_SysRole_SysUserRole]
ON [dbo].[Sys_UserRoles]
    ([RoleID]);
GO

-- Creating foreign key on [RoleID] in table 'Sys_RoleMenuButtons'
ALTER TABLE [dbo].[Sys_RoleMenuButtons]
ADD CONSTRAINT [FK_SysRole_SysRoleMenuButton]
    FOREIGN KEY ([RoleID])
    REFERENCES [dbo].[Sys_Roles]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysRole_SysRoleMenuButton'
CREATE INDEX [IX_FK_SysRole_SysRoleMenuButton]
ON [dbo].[Sys_RoleMenuButtons]
    ([RoleID]);
GO

-- Creating foreign key on [UserID] in table 'Sys_UserMenuButtons'
ALTER TABLE [dbo].[Sys_UserMenuButtons]
ADD CONSTRAINT [FK_SysUser_SysUserMenuButton]
    FOREIGN KEY ([UserID])
    REFERENCES [dbo].[Sys_Users]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysUser_SysUserMenuButton'
CREATE INDEX [IX_FK_SysUser_SysUserMenuButton]
ON [dbo].[Sys_UserMenuButtons]
    ([UserID]);
GO

-- Creating foreign key on [MenuButtonID] in table 'Sys_RoleMenuButtons'
ALTER TABLE [dbo].[Sys_RoleMenuButtons]
ADD CONSTRAINT [FK_SysMenuButton_SysRoleMenuButton]
    FOREIGN KEY ([MenuButtonID])
    REFERENCES [dbo].[Sys_MenuButtons]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysMenuButton_SysRoleMenuButton'
CREATE INDEX [IX_FK_SysMenuButton_SysRoleMenuButton]
ON [dbo].[Sys_RoleMenuButtons]
    ([MenuButtonID]);
GO

-- Creating foreign key on [MenuButtonID] in table 'Sys_UserMenuButtons'
ALTER TABLE [dbo].[Sys_UserMenuButtons]
ADD CONSTRAINT [FK_SysMenuButton_SysUserMenuButton]
    FOREIGN KEY ([MenuButtonID])
    REFERENCES [dbo].[Sys_MenuButtons]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysMenuButton_SysUserMenuButton'
CREATE INDEX [IX_FK_SysMenuButton_SysUserMenuButton]
ON [dbo].[Sys_UserMenuButtons]
    ([MenuButtonID]);
GO

-- Creating foreign key on [DicTypeID] in table 'Sys_Dictionaries'
ALTER TABLE [dbo].[Sys_Dictionaries]
ADD CONSTRAINT [FK_SysDicType_SysDictionary]
    FOREIGN KEY ([DicTypeID])
    REFERENCES [dbo].[Sys_DicTypes]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysDicType_SysDictionary'
CREATE INDEX [IX_FK_SysDicType_SysDictionary]
ON [dbo].[Sys_Dictionaries]
    ([DicTypeID]);
GO

-- Creating foreign key on [DepartmentID] in table 'Sys_Users'
ALTER TABLE [dbo].[Sys_Users]
ADD CONSTRAINT [FK_SysDepartment_SysUser]
    FOREIGN KEY ([DepartmentID])
    REFERENCES [dbo].[Sys_Departments]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysDepartment_SysUser'
CREATE INDEX [IX_FK_SysDepartment_SysUser]
ON [dbo].[Sys_Users]
    ([DepartmentID]);
GO

-- Creating foreign key on [DictionaryID] in table 'Gen_News'
ALTER TABLE [dbo].[Gen_News]
ADD CONSTRAINT [FK_SysDictionary_GenNew]
    FOREIGN KEY ([DictionaryID])
    REFERENCES [dbo].[Sys_Dictionaries]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SysDictionary_GenNew'
CREATE INDEX [IX_FK_SysDictionary_GenNew]
ON [dbo].[Gen_News]
    ([DictionaryID]);
GO

-- Creating foreign key on [RouteID] in table 'Tour_RouteScenics'
ALTER TABLE [dbo].[Tour_RouteScenics]
ADD CONSTRAINT [FK_TourRoute_TourRouteScenic]
    FOREIGN KEY ([RouteID])
    REFERENCES [dbo].[Tour_Routes]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TourRoute_TourRouteScenic'
CREATE INDEX [IX_FK_TourRoute_TourRouteScenic]
ON [dbo].[Tour_RouteScenics]
    ([RouteID]);
GO

-- Creating foreign key on [ScenicID] in table 'Tour_RouteScenics'
ALTER TABLE [dbo].[Tour_RouteScenics]
ADD CONSTRAINT [FK_TourScenic_TourRouteScenic]
    FOREIGN KEY ([ScenicID])
    REFERENCES [dbo].[Tour_Scenics]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TourScenic_TourRouteScenic'
CREATE INDEX [IX_FK_TourScenic_TourRouteScenic]
ON [dbo].[Tour_RouteScenics]
    ([ScenicID]);
GO

-- Creating foreign key on [TicketID] in table 'Tour_TicketScenics'
ALTER TABLE [dbo].[Tour_TicketScenics]
ADD CONSTRAINT [FK_TourTicket_TourTicketScenic]
    FOREIGN KEY ([TicketID])
    REFERENCES [dbo].[Tour_Tickets]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TourTicket_TourTicketScenic'
CREATE INDEX [IX_FK_TourTicket_TourTicketScenic]
ON [dbo].[Tour_TicketScenics]
    ([TicketID]);
GO

-- Creating foreign key on [ScenicID] in table 'Tour_TicketScenics'
ALTER TABLE [dbo].[Tour_TicketScenics]
ADD CONSTRAINT [FK_TourScenic_TourTicketScenic]
    FOREIGN KEY ([ScenicID])
    REFERENCES [dbo].[Tour_Scenics]
        ([ID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TourScenic_TourTicketScenic'
CREATE INDEX [IX_FK_TourScenic_TourTicketScenic]
ON [dbo].[Tour_TicketScenics]
    ([ScenicID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------